import java.awt.Dimension;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JScrollPane;


public class ResultPanel extends JPanel{
	 public ResultPanel() {
	        JPanel resultPanel = new JPanel();
	        
	        resultPanel.setPreferredSize(new Dimension(1000, 500));
			
	        refreshResults();
			
			add(resultPanel);
	 }
	 public void refreshResults(){
		 Component[] currentComponents = this.getComponents();
		 for(int i=0;i<currentComponents.length;i++){
			 this.remove(currentComponents[i]);
		 }
		 
		 DefaultTableModel tableStruct = new DefaultTableModel();
		// Create a new table instance
		JTable table = new JTable( tableStruct );
		tableStruct.addColumn("Threshold #");
		tableStruct.addColumn("Hit Count");
		tableStruct.addColumn("Miss Count");
		tableStruct.addColumn("Level Threshold Hit Rate");
		tableStruct.addColumn("Overall Threshold Hit Rate");
		
		for(int runIndex=1;runIndex<SplitSim.thresholds.size();runIndex++ ){
			tableStruct.addRow(new Object[]{"Threshold# "+(int)SplitSim.thresholds.get(runIndex).getLevel(),SplitSim.thresholds.get(runIndex).getHitCount(),SplitSim.thresholds.get(runIndex).getMissCount(),SplitSim.thresholds.get(runIndex).getHitRatio(),SplitSim.thresholds.get(runIndex).getOverallHitRatio()});
		}

		// Add the table to a scrolling pane
		JScrollPane scrollPane = new JScrollPane( table );
		scrollPane.setPreferredSize(new Dimension(900, 400));
		this.add(scrollPane);
		scrollPane.setVisible(true);
		this.setPreferredSize(new Dimension(1000, 500));
	}
}
